// pages/market/goodsDetail/goodsDetail.js
var WxParse = require('../../../wxParse/wxParse.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据 
   */
  data: {
    goods:{
      id:9,
      img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
      imgUrls: [
        'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
        'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
        'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png'
      ],
      title:'商品标题商品标题商品标题',
      tips: '商品描述 商品描述',
      price:34,
      integral:220,
      nums:1,
    }
  },
  reduce:function(){
    var that = this;
    var goods = that.data.product;
    if(goods.nums>1){
      goods.nums--;
    }else{
      goods.nums = 1;
    }
    that.setData({
      product:goods
    })
  },
  add:function(){
    var that = this;
    var goods = that.data.product;
    goods.nums++;
    that.setData({
      product: goods
    })
  },
  toorderConfirm:function(){
    var that = this;
    var id = that.data.product.id;
    var nums = that.data.product.nums;
    wx.navigateTo({
      url: '/pages/market/orderConfirm/orderConfirm?id='+id+'&&nums='+nums,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var that = this;
    wx.request({
      url: app.siteInfo.scoreroot + 'goods_one',
      method: "get",
      data: {
        id:options.id,
        uid: app.siteInfo.uid,
        pid: app.siteInfo.pid,
        com_part_id: app.siteInfo.com_part_id,
      },
      success: function (res) {
        wx.setNavigationBarTitle({
          title: res.data.list.title,//页面标题为路由参数
        })
        var article = res.data.list.content
        WxParse.wxParse('article', 'html', article, that, 0);
        res.data.list.content = article;
        var article2 = res.data.list.text
        console.log(article2);
        WxParse.wxParse('article2', 'html', article2, that, 0);
        res.data.list.text = article2;
        res.data.list.nums = 1;
        that.setData({
          product: res.data.list,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})